<script setup>
    import { sdCityList, getName, getIdCardNumber } from '@/utils/index'
    import AddData from './AddData.vue'
    
    // 列表
    let resData = $ref([])

    // 总条数
    let totalCount = $ref(0)

    // 筛选
    let filterParams = $ref({
        pageNo: 1,
        pageSize: 20,
    })

    // 列表数据加载中
    let dataLoading = $ref(false)


    const getList = () => {
        dataLoading = true

        setTimeout(() => {
            dataLoading = false
            resData = [
                { s1: getName(), s2: '男', s3: getIdCardNumber(), s4: '汉', s5: '群众', s6: '枣庄', s7: '农村低收入人口', s8: '2022-11-08', s9: '刘欢' },
                { s1: getName(), s2: '男', s3: getIdCardNumber(), s4: '汉', s5: '群众', s6: '枣庄', s7: '农村低收入人口', s8: '2022-08-30', s9: '刘欢' },
                { s1: getName(), s2: '男', s3: getIdCardNumber(), s4: '汉', s5: '群众', s6: '济南', s7: '农村低收入人口', s8: '2022-07-22', s9: '刘欢' },
                { s1: getName(), s2: '男', s3: getIdCardNumber(), s4: '汉', s5: '群众', s6: '济南', s7: '农村低收入人口', s8: '2022-06-05', s9: '刘欢' },
                { s1: getName(), s2: '男', s3: getIdCardNumber(), s4: '汉', s5: '群众', s6: '枣庄', s7: '农村低收入人口', s8: '2022-06-05', s9: '刘欢' },
                { s1: getName(), s2: '男', s3: getIdCardNumber(), s4: '汉', s5: '群众', s6: '济南', s7: '农村低收入人口', s8: '2022-04-12', s9: '刘欢' },
            ]

            for(let i = 0; i < 10; i++){
                resData.push(
                    { s1: getName(), s2: '男', s3: getIdCardNumber(), s4: '汉', s5: '群众', s6: '枣庄', s7: '农村低收入人口', s8: '2022-11-08', s9: '刘欢' }
                )
            }

            totalCount = resData.length
        }, 300);
    }
    getList()

    // 分页
    const handleCurrentChange = (page) => {
        filterParams.pageNo = page
        getList()
    }

    const handleSizeChange = (size) => {
        filterParams.pageSize = size
        getList()
    }

    // 搜索
    const hadleSearch = () => {
        filterParams.pageNo = 1
        getList()
    }

    // 重置
    const handleClickReset = () => {
        filterParams = {
            pageNo: 1,
            pageSize: 20
        }
    }

    let addData = $ref(null)
    

</script>

<template>
    <div class="health-search">
        <div class="health-search-form-warp dz-filter-wrap">
            <el-form 
                :model="filterParams" 
                :inline="true"
                :label-width="105"
                class="mt10"
            >
                <el-form-item label="所属市">
                    <el-select v-model="filterParams.sysOrgCode" placeholder=" " clearable @clear="delete filterParams.sysOrgCode">
                        <el-option
                            v-for="(item, index) in sdCityList"
                            :key="index"
                            :label="item"
                            :value="item"
                        >
                            {{ item }}
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="人员类型">
                    <el-select v-model="filterParams.type" placeholder=" " clearable @clear="delete filterParams.type">
                        <el-option
                            v-for="(item, index) in ['农村低收入人口']"
                            :key="index"
                            :label="item"
                            :value="item"
                        >
                            {{ item }}
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="姓名">
                    <el-input v-model="filterParams.name"></el-input>
                </el-form-item>
                <el-form-item label="身份证号">
                    <el-input v-model="filterParams.idCard"></el-input>
                </el-form-item>

                <div class="btn-wrap flex-center">
                    <div class="btn reset" @click="handleClickReset">重置</div>
                    <div class="btn search" @click="hadleSearch">查询</div>
                </div>
            </el-form>

        </div>

        <!-- 查询结果 -->
        <div class="search-result mt10" v-loading="dataLoading">
            <div class="result-title flex-between">
                <div>
                    查询结果
                    <span class="result-count">共{{ totalCount }}条</span>
                </div>
            </div>
            
            <el-table 
                :data="resData" 
                style="width: 100%"
                height="570"
                size="large"
                class="dz-table"
                :scrollbar-always-on="true"
            >
                <el-table-column type="index" label="序号" min-width="60" align="center" />
                <el-table-column prop="s1" label="姓名" min-width="90" align="center" />
                <el-table-column prop="s2" label="性别" min-width="90" align="center" />
                <el-table-column prop="s3" label="身份证号码" min-width="180" />
                <el-table-column prop="s4" label="民族" min-width="90" align="center" />
                <el-table-column prop="s5" label="政治面貌" min-width="120" align="center" />
                <el-table-column prop="s6" label="所属市" min-width="120" align="center" />
                <el-table-column prop="s7" label="人员类型" min-width="130" align="center" />
                <el-table-column prop="s8" label="退出日期" min-width="130" align="center" />
                <el-table-column prop="s9" label="处理人" min-width="130" align="center" />
                <el-table-column prop="v6" label="操作" min-width="100" align="center">
                    <template #default="scope">
                        <div class="table-operation flex-center">
                            <span @click="addData.showAddDialog(scope.row, 'details')">查看</span>
                            <span @click="addData.showAddDialog(scope.row, 'edit')">修改</span>
                        </div>
                    </template>
                </el-table-column>
            </el-table>

            <el-pagination 
                class="mt20" 
                background 
                layout="total, sizes, prev, pager, next" 
                :total="totalCount" 
                :page-size="filterParams.pageSize"
                @current-change="handleCurrentChange"
                @size-change="handleSizeChange"
            />

        </div>
    </div>

    <!-- 详情 -->
    <add-data ref="addData"></add-data>

</template>
